package com.idak.rdv.dao.impl;

import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.idak.rdv.dao.AppointmentDao;
import com.idak.rdv.dao.util.RdvUtils;
import com.idak.rdv.db.Appointment;

@Repository("appointmentDao")
public class AppointmentDaoImpl extends RdvHibernateDao<Appointment, Integer> implements AppointmentDao {

	@SuppressWarnings("unchecked")
	public List<Appointment> findAppointmentsByDate(String date) {
		
		Session session = getCurrentSession();
		Criteria criteria = session.createCriteria(getEntityClass());
		Date dtAppointement = RdvUtils.stringToDate(date, "dd/MM/yyyy");
		criteria.add(Restrictions.eq("dtAppointment", dtAppointement));
		List<Appointment> appointments =  criteria.list();
		
		return appointments;
	}

	public Class<Appointment> getEntityClass() {
		return Appointment.class;
	}

}
